package com.qf.cardlike.controller;

import com.github.pagehelper.PageInfo;
import com.qf.cardlike.domain.Card;
import com.qf.cardlike.response.Response;
import com.qf.cardlike.service.CadService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("card")
@RequiredArgsConstructor
public class CardController {

    private final CadService cardService;


    @PostMapping("add")
    public Response<Card> addCard(@RequestBody Card card) {
        cardService.addCard(card);
        return Response.success();
    }


    @GetMapping("view/{id}")
    public Response<Card> viewCardById(@PathVariable("id") Integer id) {
        return Response.success(cardService.selectById(id));
    }


    @GetMapping("page")
    public Response<PageInfo<Card>> viewCardByPage(Integer pageIndex, Integer pageSize) {
        return Response.success(cardService.selectCardByPage(pageIndex, pageSize));
    }


    @GetMapping("like")
    public Response<PageInfo<Card>> viewCardByPageWithIds(Integer pageIndex, Integer pageSize, String ids) {
        return Response.success(cardService.selectByIds(pageIndex, pageSize, ids));
    }
}
